#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
int main(){
  pid_t id = fork();
  if(id == 0){
    //child
    int count = 5;
    while(count--){
      printf("%d    i am child process ---->%d\n",count,getpid());
      sleep(1);
    }
    exit(0);
  }
  //parent
  sleep(10);
  //pid_t ret = wait(NULL);
  int status = 0;
  pid_t ret = waitpid(id, &status, 0);
  if(ret > 0){
    printf("father wait:%d, success! exit code:%d core dump:%d exit signal:%d\n",ret,(status>>8)&11111111,(status>>7)&1,status&1111111);
  }
  else{
    perror("wait\n");
  }
  return 0;
}
